package com.aki.ai_property.service.impl;

import com.aki.ai_property.dao.SignatureDao;
import com.aki.ai_property.dto.SignatureDto;
import com.aki.ai_property.entity.Signature;
import com.aki.ai_property.service.intf.SignatureService;
import com.aki.ai_property.util.StringUtil;
import com.aki.ai_property.vo.PageBean;
import com.aki.ai_property.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Author:WuChuangChuang
 * Date:2022/8/27 16:44
 */
@Service
public class SignatureServiceImpl implements SignatureService {
    @Autowired
    private SignatureDao dao;

    /** 新增 */
    @Override
    public Result save(Signature signature) {
        if (dao.save(signature) >0){
            return Result.ok("新增成功");
        }
        return Result.fail("新增失败");
    }

    /** 修改 */
    @Override
    public Result update(SignatureDto signatureDto) {
        if (dao.update(signatureDto) >0){
            return Result.ok("修改成功");
        }
        return Result.fail("修改失败");
    }

    /** 删除 */
    @Override
    public Result delete(int id) {
        if (dao.delete(id) >0){
            return Result.ok("删除成功");
        }
        return Result.fail("删除失败");
    }

    /** 查询 */
    @Override
    public PageBean all(String name,int page,int limit) {
        if (StringUtil.isNotEmpty(name)) {
            name="%"+name+"%";
        }
        int start = (page-1)* limit;
        return PageBean.ok(dao.selectCount(name), dao.selectPage(name, page, limit) );
    }

    /**批量删除*/
    @Override
    public Result delIds(int[] ids) {
        if (dao.delByIds(ids)>0){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }
}
